<?php

class updateMod extends commonMod
{
    // 显示管理后台首页
    public function index()
    {
        $config = $this->config;
		$ver = Xml::decode(file_get_contents('http://patch.dlcms.net/ver.xml'));		
		$ver = $ver['dlcms']['dlcms_'.$config['ver_date']];
		$ver=$ver[0];
        $this->assign('ver', $ver);
		$this->display(); 
    }

    //开始更新
    public function update()
    {

    $patch=$_POST['patch'];  //补丁地址
    $patch_admin=$_POST['patch_admin'];  //后台补丁地址
    $patch_name=$_POST['patch_name']; //补丁名称
    
    $file = file_get_contents($patch);
    if (@file_put_contents(__ROOTDIR__.'/data/cache/'.$patch_name,$file)) {
    }else{
    $this->jserror('/data/cache/"目录无写入权限！');
    exit;
    }

    $archive =  new pclzip(__ROOTDIR__.'/data/cache/'.$patch_name);
    if(!$archive->extract(PCLZIP_OPT_PATH, __ROOTDIR__)) {
    $this->jserror("解压错误 : ".$archive->errorInfo(true));
    exit;
    }

    if(!empty($patch_admin)) {
    $file2 = file_get_contents($patch_admin);
    if (@file_put_contents(__ROOTDIR__.'/data/cache/admin'.$patch_name,$file2)) {
    }else{
    $this->jserror('/data/cache/"目录无写入权限！');
    exit;
    }

    $archive2 =  new pclzip(__ROOTDIR__.'/data/cache/admin'.$patch_name);
    if(!$archive2->extract(PCLZIP_OPT_PATH, __ADMINDIR__)) {
    $this->jserror("后台解压错误 : ".$archive->errorInfo(true));
    exit;
    }
    }
    $this->jssuccess('文件更新成功，开启升级数据库！');
    }
	
	
}

?>